package com.zl.client.controller;

import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;


/**
 * @author zhouliang
 * @date 2019/11/25 21:13
 */
@Slf4j
@RestController
@RequestMapping("/consumer")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ConsumerController {

    private final RestTemplate restTemplate;

    @RequestMapping("/getProviderInfo")
    public Integer getProviderInfo() {
        ResponseEntity<List> responseEntity = restTemplate.getForEntity("http://eureka-client-provider/provider/findInstance", List.class);
        List list = responseEntity.getBody();
        log.info("调用provider服务获取到的信息为:{}", JSON.toJSONString(list));
        if (null != list) {
            return list.size();
        }
        return 0;
    }
}
